<template>
	<div>
		<vhead></vhead>
		
		<div class="container" style="margin-top: 70px;">
			<div class="row">
				<div class="col-sm-9 film-left">
					<div class="fl-head">
						<filmType :dataJson="bookType"></filmType>
					</div>
					<listContent :dataJson="bookAll"></listContent>
				</div>
			</div>
		</div>
		
		<vfoot></vfoot>
	</div>
</template>

<script>
	import Vhead from "../public/VHead"
	import ListContent from "../public/ListContent"
	import FilmType from "../public/FilmType"
	import VFoot from "../public/VFoot"
	import Qs from 'qs'
	export default {
		data () {
		    return {
		    	bookType : [],
		    	bookAll :[]
		    }
		},
		mounted ($route) {
	 		this.$nextTick(()=>{
	 			let _this = this; 
	 			let typeId = "all"
	 			if(_this.$route.params.id){
	 				typeId = _this.$route.params.id
	 			}
	 			//获取所有书籍
	 			let data ={
	 				"typeId" : typeId
	 			}; 
        		_this.$axios({
                    method: "post",
                    data: Qs.stringify(data),
                    url: "http://www.qixiaocheng.cn/public/index.php/index/Book/findBookBySome",
                })
                .then(function(res) {
                	for(var i = 0;i<res.data.length;i++){
  						res.data[i]["imgUrl"] = 'http://www.qixiaocheng.cn/public/uploads/'+res.data[i]["bookUrl"] ;
  						res.data[i]["id"] = res.data[i]["bookId"];
  						res.data[i]["name"] = res.data[i]["bookName"];
  						res.data[i]["url"] = '/bookDetail/'+res.data[i]["bookId"];
  					}
                	_this.bookAll = res.data;
               	})
                .catch(function(err) {
                   console.log(err);
               	});
	 			
	 			//获取所有书籍的类型
	 			_this.$axios({
                    method: "post",
                    url: "http://www.qixiaocheng.cn/public/index.php/index/Booktype/findAllBookType",
                })
                .then(function(res) {
                	for(var i = 0;i<res.data.length;i++){
  						res.data[i]["id"] = res.data[i]["type_id"];
  						res.data[i]["name"] = res.data[i]["type_name"];
  						res.data[i]["url"] = '/book/'+res.data[i]["type_id"];
  					}
                	_this.bookType = res.data;
               	})
                .catch(function(err) {
                   console.log(err);
               	});
               	
	 		})
 		},
		components:{
			"vhead" : Vhead,
			"filmType" : FilmType,
			"vfoot" : VFoot,
			"listContent" : ListContent
		}
	}
</script>

<style scoped>
	.film-left{
		border-left: 1px solid #dfdfdf;
		border-right: 1px solid #dfdfdf;
	}
	.fl-head{
		border-bottom: 1px solid #dfdfdf;
	}
	
</style>